package lol.clann.minecraft.springboot.bukkit.plugin.logger;

import lol.clann.minecraft.springboot.bukkit.plugin.bukkit.BukkitLogger;
import org.slf4j.Logger;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author pyz
 * @date 2019/5/5 11:11 PM
 */
public class LoggerFactory {
    private static final Map<String, Logger> cache = new ConcurrentHashMap<>();

    public static Logger getLogger(String name) {
        Logger logger = cache.get(name);
        if (logger == null) {
            synchronized (cache) {
                logger = cache.get(name);
                if (logger == null) {
                    try {
                        logger = new BukkitLogger(name);
                        cache.put(name, logger);
                    } catch (Throwable e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
        return logger;
    }

    public static Logger getLogger(Class<?> clazz) {
        return getLogger(clazz.getSimpleName());
    }

}
